<?
class ManagePromotionListForm extends Form
{
    var $hotel = array();

    function ManagePromotionListForm()
    {
        Form::Form("ManageChiefForm");
        $this->link_js('javascript/tiny_mce/tinymce.min.js');

        $this->link_css("style/hotel.css");
        $this->link_css("style/paging.css");
    }

    function draw()
    {
        global $display;
        $display->add("WEB_ROOT",WEB_ROOT);
        $display->add("WEB_DIR",WEB_DIR);
        $this->beginForm(true);
        $item_perpage 	= 50;
        $con_arr = array();

        //Lọc theo trạng thái ks
        $hotel_status = Url::getInt("hotel_status",10);
        $display->add('hotel_status', $hotel_status);
        if($hotel_status!==0){
            if($hotel_status==10){
                $con_arr[] = "(status > 0)";
            }else{
                $con_arr[] = "(status=$hotel_status)";
            }
        }else{
            $con_arr[] = "(status > 0)";
        }
        $hotel_name = Url::get("hotel_name",'');
        $display->add('hotel_name', $hotel_name);
        if($hotel_name){
            $con_arr[] = '(`name` LIKE "%'.DB::escape($hotel_name).'%")';
        }
        //Lọc theo Id ks
        $pos = Url::get("pos",'');
        $display->add('pos', $pos);
        if($pos){
            $con_arr[] = '(pos='.(int)$pos.')';
        }


        $condition = implode($con_arr,' AND ');
        $condition .= ' ORDER BY id DESC';

        $total 	= Db_Promotion::total($condition);
        $display->add('paging', ECPaging::pagingSE($limit, $total, $item_perpage, 10, 'page_no',true, 'Banner'));
        $hotels = Db_Promotion::getPromotions($limit, $condition);

        $user_ids = '';

        foreach ($hotels as &$hotel){
            $hotel['can_edit'] 	= (User::have_permit('hotel_edit') || Db_Hotel::have_permit_manage($hotel,User::id()));
        }

        $user_admins 	= array();
        if($user_ids != ''){
            $user_admins 	= Db_User::getUsersByIDs($user_ids);
        }
        $display->add('user_admins', $user_admins);
        $display->add('status', array(1=>"Hiện",2=>"Ẩn",-1=>"Đã xóa"));
        $display->add('hotels', $hotels);

        $display->add('can_edit', 			User::have_permit('hotel_edit'));
        $display->add('can_add', 			User::have_permit('hotel_add'));
        $display->add('can_delete', 		User::have_permit('hotel_delete'));
        $display->add('href', urldecode(Url::build_all(array('cmd','act'))));

        if (User::is_admin()) {
            $display->add('is_admin', true);
        }
        $display->output('ManageChief');
        $this->endForm();
    }

    function on_submit()
    {
        global $display;


    }
}